Page({
  data: {
    username: '',
    password: ''
  },
  onUsernameInput(e) {
    this.setData({ username: e.detail.value });
  },
  onPasswordInput(e) {
    this.setData({ password: e.detail.value });
  },
  onLogin() {
    const { username, password } = this.data;
    if (!username || !password) {
      wx.showToast({ title: '请输入用户名和密码', icon: 'none' });
      return;
    }
    wx.request({
      url: 'http://localhost:3000/api/admin/login',
      method: 'POST',
      data: { username, password },
      success(res) {
        if (res.data && res.data.code === 0) {
          wx.showToast({
            title: '登录成功',
            icon: 'success',
            success() {
              // 跳转到商品管理页
              wx.redirectTo({
                url: '/pages/admin/goods/index'
              });
            }
          });
        } else {
          wx.showToast({ title: res.data.message || '登录失败', icon: 'none' });
        }
      },
      fail() {
        wx.showToast({ title: '网络错误', icon: 'none' });
      }
    });
  }
}); 